package AOP;

import AOP.impl.AOPTest;
import com.zc.dto.PersonAOP;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.Invocation;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.Advisor;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;

import java.lang.reflect.Method;

/**
 * 纯Java的方式实现切面(拦截)技术
 */
public class JavaAOP {
    //和动态代理类似
    @Test
    public void demo(){

        //获取切面规则,主要是面向切面的方法,以及切入点的位置(这里有before,after,around三种)
        AOPPoint  aop = new AOPTest();
        Advisor advisor = aop.rule(".*.print.*","before");

        //获取代理后的对象
        PersonAOP p2 = (PersonAOP) AOPFactory.proxy(new PersonAOP(),advisor);

        p2.run();
        p2.print();//不会拦
        p2.run(3333);


    }
}
